import {useState,useEffect} from 'react'
export function useWinSize(){
  const [size,setSize] = useState({w:window.innerWidth,h:window.innerHeight})
  // 监听窗口变化，更新size(组件挂载完毕)
  function onResize(){
    setSize({w:window.innerWidth,h:window.innerHeight})
  }
  useEffect(()=>{
    window.addEventListener("resize",onResize);
    // 组件卸载移除监听
    return ()=> window.removeEventListener("resize",onResize);
  },[])
  return  size;
}
// 10:15